

import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;

import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DialerPanel extends javax.swing.JPanel implements ActionListener {
	
	private JTextField tfToUser;
	private JButton bCall;
	private JButton bHangup;

	SIPTalkUI sipTalkUI;
	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	
	public DialerPanel(SIPTalkUI sipTalkUI) {
		super();
		this.sipTalkUI = sipTalkUI;
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(289, 167));
			{
				tfToUser = new JTextField();
			}
			{
				bCall = new JButton();
				bCall.setText("Call");
			}
			{
				bHangup = new JButton();
				bHangup.setText("Hang Up");
				bHangup.setEnabled(false);
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(23, 23)
				.addComponent(tfToUser, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				.addGap(23)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(bCall, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(bHangup, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(77, 77));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(51, 51)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(bCall, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE)
				        .addGap(26)
				        .addComponent(bHangup, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addGap(8)
				        .addComponent(tfToUser, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 12, Short.MAX_VALUE)))
				.addContainerGap(57, 57));
			
			bCall.addActionListener(this);
			bHangup.addActionListener(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void actionPerformed(ActionEvent ae) {
		String eventString = ae.getActionCommand();
		if(eventString.equals("Call")) {
			if(!tfToUser.getText().equals("")) {
				bCall.setEnabled(false);
				bHangup.setEnabled(true);
				sipTalkUI.sipTalk.invite(tfToUser.getText());
			} 
		} else if(eventString.equals("Hang Up")) {
			bCall.setEnabled(true);
			bHangup.setEnabled(false);
			sipTalkUI.sipTalk.cancel();
		}
	}
	
	public void acceptCall() {
		bCall.setEnabled(false);
		bHangup.setEnabled(true);
	}
	
	public void hangupCall() {
		bCall.setEnabled(true);
		bHangup.setEnabled(false);
	}

}
